package org.fly.jingwei.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.File;

import org.fly.jingwei.ext.core.PropsUI;
import org.fly.jingwei.util.KettleEncrypt;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.Props;
import org.fly.jingwei.util.task.CarteTaskManager;
import org.pentaho.di.core.exception.KettleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author leo.jie (weixiao.me@aliyun.com)
 * @version 1.0
 * @organization bigdata
 * @website https://www.jielongping.com
 * @date 2020/5/30 4:09 下午
 * @since 1.0
 */
@WebListener
public class SystemLoadListener implements ServletContextListener {
    private static final Logger logger = LoggerFactory.getLogger(SystemLoadListener.class);
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        logger.info("开始初始化Kettle的环境>>>>>>>>>>>>>>>>>>>>>>>");
        String userHome = System.getProperties().getProperty("user.home");
        String kettleHome = userHome + File.separator +
                ".jingwei" + File.separator + "kettle"+File.separator;
        System.setProperty("KETTLE_HOME", kettleHome);
        try {
            KettleEnvironment.init();
            CarteTaskManager.startThread(1);
            PropsUI.init( "KettleWebConsole", Props.TYPE_PROPERTIES_KITCHEN );
            logger.info("成功初始化Kettle的环境>>>>>>>>>>>>>>>>>>>>>>");
        } catch (KettleException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
